import { ClockPage } from './clock/clock';
import { Component } from '@angular/core';
import { NavController, NavParams, ViewController } from 'ionic-angular';
import { DynamicPage } from './dynamic/dynamic';
import { Api } from '../../providers/api-service';
import { NewChallengePage } from './new-challenge/new-challenge';
/**
 * 发布
 * Ionic pages and navigation.
 */
@Component({
  selector: 'page-my-add-issuance',
  templateUrl: 'my-add-issuance.html',
})
export class MyAddIssuancePage {
  btnlist = [];
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    public viewCtrl: ViewController,
    public api: Api
  ) {
    this.btnlist = [
      { name: "发布挑战", imgs: "assets/imgs/img_home/Group 5@3x.svg" },
      { name: "打卡", imgs: "assets/imgs/img_home/Group 6@3x.svg" },
      { name: "动态", imgs: "assets/imgs/img_home/Group 7@3x.svg" }
    ];
  }

  ionViewDidLoad() {
    console.log('发布  MyAddIssuancePage');

  }

  btsClick(item) {
    if (item.name == "发布挑战") {
      this.isChallengeOk();
    } else if (item.name == "打卡") {
      this.navCtrl.push(ClockPage);
    } else if (item.name == "动态") {
      this.navCtrl.push(DynamicPage);
    }
  }
  
  /**
   * 关闭页面
   */
  dismiss() {
    this.viewCtrl.dismiss();
  }

  /**
   判断发布挑战 次数是否用完 
   */
  isChallengeOk() {
    this.api.postBody("V1/UserDekaronVerification", {})
      .then(data => {
        if (data.Data == "true") {
          this.navCtrl.push(NewChallengePage);
        } else {
          this.api.showNoticeByToast(1, "免费挑战次数已到，请充值。");
        }
      })
  }

}
